import { ref, onMounted, onBeforeUnmount } from 'vue'
export default function  () {
    const x = ref(-1)
    const y = ref(-1)

    // 点击事件的回调函数
    function clickHandle(event: MouseEvent) {
        x.value = event.pageX
        y.value = event.pageY
    }

    // 页面加载完毕了，在进行点击的操作
    onMounted(() => {
        window.addEventListener('click', clickHandle)
    })
    // 页面卸载前
    onBeforeUnmount(() => {
        window.removeEventListener('click', clickHandle)
    })
    return {
        x, y
    }
}